<template>
  <div id="home">
    <home-header/>
    <home-swiper :SwiperList="SwiperList" />
    <home-icons :list="iconList" />
    <home-recommend :recommendList="recommendList" />
    <home-weekend :weenkendList="weenkendList" />
  </div>
</template>

<script>
import HomeHeader from './components/Header.vue'
import HomeSwiper from './components/Swiper.vue'
import HomeIcons from './components/Icons.vue'
import HomeRecommend from './components/Recommend.vue'
import HomeWeekend from './components/Weenkend.vue'
import axios from 'axios'
import {mapState} from 'vuex'

export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeWeekend
  },
  data () {
    return {
      // city: '',
      lastCity: '',
      SwiperList: [],
      iconList: [],
      recommendList: [],
      weenkendList: []
    }
  },
  computed: {
    ...mapState(['city'])
  },
  methods: {
    getHomeInfo () {
      axios.get('/api/index.json?city=' + this.city)
        .then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc (res) {
      const Data = res.data.data
      // this.city = Data.city
      this.SwiperList = Data.SwiperList
      this.iconList = Data.iconList
      this.recommendList = Data.recommendList
      this.weenkendList = Data.weenkendList
    }
  },
  mounted () {
    this.lastCity = this.city
    this.getHomeInfo()
  },
  activated () {
    if (this.lastCity !== this.city) {
      this.lastCity = this.city
      this.getHomeInfo()
    }
  }
}
</script>

<style>
#home{
  background: rgb(245, 235, 237);
}
</style>
